package de.cbf.cam.dice.entities;

import java.beans.IndexedPropertyChangeEvent;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;

public class RollDataCheck extends RollDataModifier{

	private int 	base;

	private boolean success;

	private boolean ignoreNegatives;

	public static final int PropertyIndexBase	 		 = 9;
	public static final int PropertyIndexSuccess 		 = 10;
	public static final int PropertyIndexIgnoreNegatives = 11;

	public RollDataCheck() {
		super();
		propertyChange.addPropertyChangeListener(new PCLSuccess());
	}


	public boolean isIgnoreNegatives() {
		return ignoreNegatives;
	}

	public void setIgnoreNegatives(boolean ignoreNegatives) {
		if(this.ignoreNegatives != ignoreNegatives){
			this.ignoreNegatives = ignoreNegatives;
			propertyChange.fireIndexedPropertyChange("IgnoreNegatives", PropertyIndexIgnoreNegatives,null,ignoreNegatives);
		}
	}

	public 	boolean isSuccess() {
		return success;
	}

	public void setSuccess(boolean success) {
		if(this.success != success){
			this.success = success;
			propertyChange.fireIndexedPropertyChange("Success", PropertyIndexSuccess,null,success);
		}
	}


	public int getBase() {
		return base;
	}

	public void setBase(int base) {
		if(this.base != base){
			this.base = base;
			propertyChange.fireIndexedPropertyChange("Base", PropertyIndexBase,null,base);
		}
	}
	private class PCLSuccess implements PropertyChangeListener{
		@Override
		public void propertyChange(PropertyChangeEvent evnt) {
			if (evnt instanceof IndexedPropertyChangeEvent) {
				IndexedPropertyChangeEvent idxEvent = (IndexedPropertyChangeEvent) evnt;
				switch (idxEvent.getIndex()) {
				case PropertyIndexRolls:
					{
						int modifiedBase = base - getModifierValue();
						if(rolls[0]> modifiedBase){
							setSuccess(false);
						}else{
							setSuccess(true);
						}
						break;
					}
				}
			}
		}
	}
}